<!-- 系统设置板块  -- 平台信息页面 -->
<template>
	<div>
		<el-tabs type="border-card">
			<el-tab-pane label="基础资料">
				<r-search ref="search" labelWidth="150px" labelPosition="right" :searchData="searchData"
					:searchForm="searchForm" :searchHandle="searchHandle" :inline="false" :searchRules="searchRules" />
			</el-tab-pane>
			<el-tab-pane label="运营资料">
				<r-search ref="operateInfo" labelWidth="300px" labelPosition="right" :searchData="operateData"
					:searchForm="operateForm" :searchHandle="operateHandle" :inline="false"
					:searchRules="operateRules" />
			</el-tab-pane>

			<!--        <el-tab-pane label="富文本管理">-->
			<!--          <div class="c1">-->
			<!--            <div>-->
			<!--              <div>关于我们:</div>-->
			<!--              <div>-->
			<!--                <r-tinymce v-model="value1"></r-tinymce>-->
			<!--              </div>-->
			<!--            </div>-->

			<!--            <div>-->
			<!--              <div>用户协议:</div>-->
			<!--              <div>-->
			<!--                <r-tinymce v-model="value2"></r-tinymce>-->
			<!--              </div>-->
			<!--            </div>-->

			<!--            <div style="text-align: center;margin-top:30px;"><el-button @click="submit2" type="primary">保存</el-button></div>-->
			<!--          </div>-->

			<!--        </el-tab-pane>-->
		</el-tabs>
	</div>
</template>

<script>
export default {
	name: 'platform_information',
	data() {
		return {
			value1: '',
			value2: '',
			searchData: {
				projectName: '',
				logoUrl: '',
				serverTel: '',
				email: '',
				workTime: '',
				workTimeStart: '',
				workTimeEnd: '',
				company: '',
				address: ''
			},
			searchForm: [
				{ type: 'input', label: '项目名称', placeholder: '项目名称', prop: 'projectName', width: 200 },
				{ type: 'upload', label: '项目logo', prop: 'logoUrl', width: 200, success: (response, file, fileList) => this.onsuccess(response, file, fileList) },
				{ type: 'input', label: '工作电话', placeholder: '工作电话', prop: 'serverTel', width: 200 },
				{ type: 'input', label: '官方邮箱', placeholder: '官方邮箱', prop: 'email', width: 250 },
				{ type: 'time', label: '工作时间开始', placeholder: '工作时间开始', prop: 'workTimeStart', width: 200 },
				{ type: 'time', label: '工作时间结束', placeholder: '工作时间结束', prop: 'workTimeEnd', width: 200 },
				{ type: 'input', label: '公司名称', placeholder: '公司名称', prop: 'company', width: 200 },
				{ type: 'input', label: '公司地址', placeholder: '公司地址', prop: 'address', width: 200 }
			],
			searchHandle: [{ type: 'primary', label: '保存', handle: e => this.elFormSubmit() }],
			searchRules: {
				projectName: [{ required: true, message: '请输入', trigger: 'blur' }],
				logoUrl: [{ required: true, message: '请上传', trigger: 'blur' }],
				serverTel: [{ required: true, message: '请输入', trigger: 'blur' }],
				email: [{ required: true, message: '请输入', trigger: 'blur' }],
				workTimeStart: [{ required: true, message: '请输入', trigger: 'blur' }],
				workTimeEnd: [{ required: true, message: '请输入', trigger: 'blur' }],
				company: [{ required: true, message: '请输入', trigger: 'blur' }],
				address: [{ required: true, message: '请输入', trigger: 'blur' }]
			},

			// 运营资料  start
			operateData: {
				id: '',
				wxAppId: '', // 小程序APPID
				wxSecrect: '', // 小程序秘钥Secrect
				wxMchName: '', // 商户名称
				wxMchId: '', // 商户号
				wxMchKey: '', // 微信商户Key
				gzhAppId: '', // 公众号APPID
				gzhSecrect: '', // 公众号秘钥Secrect
				wxCertPath: '', // 证书路径（需要调上传接口）
				wxPemkeyPath: '', // 私钥证书key.pem路径	（需要调上传接口）
				wxSerialNo: '', // 证书序列号
				msgTemplateId: '', // 公众号消息(通用)模板id
				appletTemplate1: '', // 小程序消息(通用)模板id （结算用）
				appletTemplate2: '', // 小程序消息(通用)模板id （结束订单用）
				smsAccessKeyId: '', // 短信keyid
				smsAccessKeySecret: '', // 短信key
				smsSignName: '', // 短信签名名称
				smsCode: '' // 短信验证码模板code
			},
			operateForm: [
				{ type: 'input', label: '小程序APPID	', placeholder: '', prop: 'wxAppId', width: 400 },
				{ type: 'input', label: '小程序秘钥Secrect', placeholder: '', prop: 'wxSecrect', width: 400 },
				{ type: 'input', label: '商户名称', placeholder: '', prop: 'wxMchName', width: 400 },
				{ type: 'input', label: '商户号', placeholder: '', prop: 'wxMchId', width: 400 },
				{ type: 'input', label: '微信商户Key', placeholder: '', prop: 'wxMchKey', width: 400 },
				{ type: 'input', label: '公众号APPID', placeholder: '', prop: 'gzhAppId', width: 400 },
				{ type: 'input', label: '公众号秘钥Secrect', placeholder: '', prop: 'gzhSecrect', width: 400 },
				{ type: 'input', label: '证书路径（需要调上传接口）', placeholder: '', prop: 'wxCertPath', width: 400 },
				{ type: 'input', label: '私钥证书key.pem路径（需要调上传接口）', placeholder: '', prop: 'wxPemkeyPath', width: 400 },
				{ type: 'input', label: '证书序列号', placeholder: '', prop: 'wxSerialNo', width: 400 },
				{ type: 'input', label: '公众号消息(通用)模板id', placeholder: '', prop: 'msgTemplateId', width: 400 },
				{ type: 'input', label: '小程序消息(通用)模板id （结算用）', placeholder: '', prop: 'appletTemplate1', width: 400 },
				{ type: 'input', label: '小程序消息(通用)模板id （（结束订单用）', placeholder: '', prop: 'appletTemplate2', width: 400 },
				{ type: 'input', label: '短信keyid', placeholder: '', prop: 'smsAccessKeyId', width: 400 },
				{ type: 'input', label: '短信key', placeholder: '', prop: 'smsAccessKeySecret', width: 400 },
				{ type: 'input', label: '短信签名名称', placeholder: '', prop: 'smsSignName', width: 400 },
				{ type: 'input', label: '短信验证码模板', placeholder: '', prop: 'smsCode', width: 400 }
			],
			operateHandle: [{ type: 'primary', label: '保存', handle: e => this.elOperateFormSubmit() }],
			operateRules: {
				/* wxAppId: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxSecrect: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxMchName: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxMchId: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxMchKey: [{ required: true, message: '请输入', trigger: 'blur' }],
				gzhAppId: [{ required: true, message: '请输入', trigger: 'blur' }],
				gzhSecrect: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxCertPath: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxPemkeyPath: [{ required: true, message: '请输入', trigger: 'blur' }],
				wxSerialNo: [{ required: true, message: '请输入', trigger: 'blur' }],
				msgTemplateId: [{ required: true, message: '请输入', trigger: 'blur' }],
				appletTemplate1: [{ required: true, message: '请输入', trigger: 'blur' }],
				appletTemplate2: [{ required: true, message: '请输入', trigger: 'blur' }],
				smsAccessKeyId: [{ required: true, message: '请输入', trigger: 'blur' }],
				smsAccessKeySecret: [{ required: true, message: '请输入', trigger: 'blur' }],
				smsSignName: [{ required: true, message: '请输入', trigger: 'blur' }],
				smsCode: [{ required: true, message: '请输入', trigger: 'blur' }] */
			}
			// 运营资料  end
		}
	},
	mounted() {
		this.getData()
		// this.getOperateConfig()
	},
	methods: {
		async getData() {
			var res = await this.apis.aboutUs_getInfo({})
			var data = res.data || {}
			this.searchData.projectName = data.projectName
			this.searchData.logoUrl = data.logoUrl
			this.searchData.serverTel = data.serverTel
			this.searchData.email = data.email
			this.searchData.workTimeStart = data.workTime.split('-')[0]
			this.searchData.workTimeEnd = data.workTime.split('-')[1]
			this.searchData.company = data.company
			this.searchData.address = data.address
			this.searchData.id = data.id
		},
		async getOperateConfig() {
			const res = await this.apis.getOperateConfig()
			this.operateData = res.data
		},
		onsuccess(response, file, fileList) {
			console.log(response)
			this.searchData.logoUrl = response.fileName
		},
		elFormSubmit() {
			this.$refs.search.$refs.ruleForm.validate(valid => {
				if (valid) {
					this.submit()
				}
			})
		},
		elOperateFormSubmit() {
			this.$refs.operateInfo.$refs.ruleForm.validate(valid => {
				if (valid) {
					this.operateSubmit()
				}
			})
		},
		// 运营资料编辑
		async operateSubmit() {
			const res = await this.apis.editOperateConfig(this.operateData)
			this.$message({
				message: '操作成功',
				type: 'success'
			})
		},
		async submit() {
			var res = await this.apis.aboutUs_saveOrUpdate({
				projectName: this.searchData.projectName,
				logoUrl: this.searchData.logoUrl,
				serverTel: this.searchData.serverTel,
				email: this.searchData.email,
				workTime: this.searchData.workTimeStart + '-' + this.searchData.workTimeEnd,
				company: this.searchData.company,
				address: this.searchData.address,
				id: this.searchData.id
			})
			this.$message({
				message: '操作成功',
				type: 'success'
			})
		},
		async submit2() {
			var res = await this.apis.saveInfo({
				aboutAs: this.value1,
				protocol: this.value2
			})
			this.$message({
				message: '操作成功',
				type: 'success'
			})
		}
	}
}
</script>

<style scoped lang="scss">
.c1 {
	>div {
		>div:nth-child(1) {
			line-height: 40px;
			font-weight: bold;
			font-size: 18px;
		}
	}
}
</style>
